const express = require('express');
const db = require('../uilit/mysql')

const router = express.Router();


router.post('/login', function(req, res) {
    const sql1 = `SELECT* FROM seeker WHERE s_tel='${req.body.username}' AND s_password='${req.body.password}';`
    const sql2 = `SELECT* FROM company WHERE c_tel='${req.body.username}' AND c_password='${req.body.password}';`
    if (req.body.Id == 1) {
        db.query(sql1, function(err, data) {
            if (err) {
                console.log(err)
            } else {
                if (data.length) {
                    req.session.userSession=data;
                    res.send({msg:'登录成功!',data:data})
                } else {
                    res.send({msg:'账号或密码不正确,请重新登录!',data:data})
                }
            }
        })
    }


    if (req.body.Id == 2) {
        db.query(sql2, function(err, data) {
            if (err) {
                console.log(err)
            } else {
                if (data.length) {
                    req.session.userSession=data;
                    res.send({msg:'登录成功!',data:data})
                } else {
                    res.send({msg:'账号或密码不正确,请重新登录!',data:data})
                }
            }
        })
    }

});


module.exports = router;